package scripting;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;

public class BashScriptExecuter implements ScriptExecuter {

	@Override
	public void executeScript(File scriptFile) throws IOException {
		// precondition: scriptFile exists
		// postcondition: scriptFile is being executed
		ProcessBuilder pb = new ProcessBuilder("python", scriptFile.getPath());
		Process p = pb.start();
		BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
		String line;
		while (null != (line = br.readLine())) {
			System.out.println(line);
		}

	}

	public static void main(String[] args) throws IOException {
		// System.out.println(System.getenv());
		File f = new File("c:\\dev\\python\\test.py");
		// System.out.println("python " + f.getPath());
		new BashScriptExecuter().executeScript(f);
	}

}
